package com.dart.sys.mq.consumer.queue;

import java.util.Enumeration;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import com.dart.sys.entity.SysOperateLog;

@Component
public class TestQueueReceiver {
	
	@JmsListener(destination="test.queue.text")
	public void queueReceiveMessage(Message message) {
		try {
			System.out.println("QueueReceiver接收到消息:"+((TextMessage)message).getText());
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
	@SuppressWarnings("unchecked")
	@JmsListener(destination="test.queue.map")
	public void receiveMapMessage(MapMessage message) {
		try {
			Enumeration<Object> mapNames = message.getMapNames();
			while (mapNames.hasMoreElements()) {
				String key = (String) mapNames.nextElement();
				System.out.println(key+"==="+message.getString(key));
				
			}
        } catch (JMSException e) {
            e.printStackTrace();
        }
	}
	
	@JmsListener(destination="test.queue.object")
	public void receiveObjectMessage(Message message) {
		if (message instanceof ObjectMessage) {
			try {
				ObjectMessage msg = (ObjectMessage) message;
				SysOperateLog log = (SysOperateLog) msg.getObject() ;
				System.out.println(log.getOperate());
				
			} catch (JMSException e) {
				e.printStackTrace();
			}
		}
	}
}
